<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const posts=[
            {title:'I love javascript',author:'yang',id:1},
            {title:'css',author:'yang',id:2},
        ];
    //     posts.push({
    //         title:'webpack',author:'xiang',id:3
    //     })
    //    localStorage.setItem('posts',JSON.stringify(posts))
    const authors=[
        {name:'yang',hometown:'yichun',bio:'面向字节'}
    ]
    function getpostbyid(id){
        // const post=posts.find(post=>post.id==id)
        // const{author}=post;
        // console.log(authors.find(item=>item.name==author));
        // return post
        return new Promise((resolve,reject)=>{

// resolve()
setTimeout(()=>{
    console.log('++++++++');
    const post=posts.find(post=>post.id==id);
    // console.log(post);
    if(post){
        resolve(post);
    }else{
        reject()
    }
    
},200)
        })
    }
   getpostbyid(1)
   .then((data)=>{
    //    console.log(data);
    const{author}=data;
    console.log(authors.find(item=>item.name==author));
   })
   .catch(()=>{
       console.log('出错了');
   })
    </script>
</body>
</html>